package cn.wolfcode.util;

import cn.wolfcode.domain.Employee;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.security.PublicKey;
import java.util.List;

public class UserContext {
    public static final String EMPLOYEE_IN_SESSION="EMPLOYEE_IN_SESSION";
    public static final String PERMISSION_IN_SESSION="PERMISSION_IN_SESSION";

    public  static HttpSession getSession(){
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        return requestAttributes.getRequest().getSession();
    }
    public static Employee getCurrentUser(){
        return (Employee)getSession().getAttribute(EMPLOYEE_IN_SESSION);
    }
    public static void setCurrentUser(Employee employee){
        getSession().setAttribute(EMPLOYEE_IN_SESSION,employee);
    }
    public static List<String> getPermissionExpression(){
        return (List<String>)getSession().getAttribute(PERMISSION_IN_SESSION);
    }
    public static void setPermissionExpression(List<String> permissionExpressions){
        getSession().setAttribute(EMPLOYEE_IN_SESSION,permissionExpressions);
    }
}